package com.jt.www.util.mail;


import com.jt.www.model.mail.dto.MailDTO;
import com.jt.www.util.DateUtils;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author: xuxinku
 * @Date: 2019/6/16 9:56
 * @ModifiedDate：
 * @Copyright:江泰保险股份有限公司
 */
public class WordAction {


    public String wordTest(String ftlType, MailDTO mailDTO) {

        /** 用于组装word页面需要的数据 */
        Map<String, String> dataMap = new HashMap<String, String>();

        dataMap.put("user", mailDTO.getUserName());
        List<String> policyNo = mailDTO.getPolicyNo();
        StringBuilder policyNos = new StringBuilder();
        for (String pol : policyNo) {
            policyNos.append(pol + ". ");
        }
        dataMap.put("policyNo", policyNos + "");
        dataMap.put("orderNo", mailDTO.getOrderNo());
        dataMap.put("premium", mailDTO.getPremium());
        dataMap.put("productName", mailDTO.getProductName());
        //用户中心修改后 更改
        dataMap.put("account", mailDTO.getBank());
        dataMap.put("bank", mailDTO.getAccount());

        dataMap.put("number", mailDTO.getNumber());
        dataMap.put("date", DateUtils.getCurrentTime());
        dataMap.put("startDate", mailDTO.getStartDate());

        String email = sdEmail(mailDTO.getRegion().replace(" ", ""));
        dataMap.put("region", mailDTO.getRegion());
        dataMap.put("email", email);

        //String filePath = "D:/JB/";
        //String filePath =System.getProperty("java.io.tmpdir")+ File.separator;
        String filePath = System.getProperties().getProperty("user.home") + File.separator;

        System.out.println("查看临时路径=======》" + filePath);
        //文件唯一名称
        String fileOnlyName = "保费支付通知.doc";
        /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/
        String WJ = "";
        if ("1".equals(ftlType)) {
            //WJ = WordUtil.createWord(dataMap, "06test.ftl", filePath, fileOnlyName);
            WJ = WordUtil.createWord(dataMap, "06ZF.ftl", filePath, fileOnlyName);
        } else if ("2".equals(ftlType)) {
            WJ = WordUtil.createWord(dataMap, "YN.ftl", filePath, fileOnlyName);
        } else if ("3".equals(ftlType)) {
            //WJ = WordUtil.createWord(dataMap, "SD.ftl", filePath, fileOnlyName);
            WJ = WordUtil.createWord(dataMap, "SDZF.ftl", filePath, fileOnlyName);
        } else if ("4".equals(ftlType)) {
            WJ = WordUtil.createWord(dataMap, "SXZF.ftl", filePath, fileOnlyName);
        } else if ("5".equals(ftlType)) {
            WJ = WordUtil.createWord(dataMap, "GD.ftl", filePath, fileOnlyName);
        }

        return WJ;
    }

    /**
     * 通过山东各市取出投保单号
     *
     * @return
     */
    public String sdEmail(String region) {
        String email = "";

        HashMap<String, String> map = new HashMap<>();
        map.put("济南市", "jinan.yyb@jiangtai.com");
        map.put("潍坊市", "weifang.yyb@jiangtai.com");
        map.put("聊城市", "liaocheng.yyb@jiangtai.com");
        map.put("济宁市", "jining.yyb@jiangtai.com");
        map.put("烟台市", "yantai.yyb@jiangtai.com");
        map.put("威海市", "weihai.yyb@jiangtai.com");
        map.put("淄博市", "zibo.yyb@jiangtai.com");
        map.put("滨州市", "binzhou.yyb@jiangtai.com");
        map.put("德州市", "dezhou.yyb@jiangtai.com");
        map.put("莱芜市", "laiwu.yyb@jiangtai.com");
        map.put("临沂市", "linyi.yyb@jiangtai.com");
        map.put("日照市", "rizhao.yyb@jiangtai.com");
        map.put("东营市", "dongying.yyb@jiangtai.com");
        map.put("枣庄市", "zaozhuang.yyb@jiangtai.com");
        map.put("菏泽市", "heze.yyb@jiangtai.com");
        map.put("泰安市", "taian.yyb@jiangtai.com");
        //山西
        map.put("太原市", "taiyuan.xzx@jiangtai.com");
        map.put("大同市", "datong.xzx@jiangtai.com");
        map.put("朔州市", "shuozhou.xzx@jiangtai.com");
        map.put("忻州市", "xinzhou.xzx@jiangtai.com");
        map.put("吕梁市", "lvliang.xzx@jiangtai.com");
        map.put("阳泉市", "yangquan.xzx@jiangtai.com");
        map.put("长治市", "changzhi.xzx@jiangtai.com");
        map.put("晋城市", "jincheng.xzx@jiangtai.com");
        map.put("晋中市", "jinzhong.xzx@jiangtai.com");
        map.put("临汾市", "linfen.xzx@jiangtai.com");
        map.put("运城市", "yuncheng.xzx@jiangtai.com");
        //遍历map
        for (String key : map.keySet()) {
            System.out.println("K== " + key + "V== " + map.get(key));
            //校验传来的key是否存在map中
            if (region.equals(key)) {
                email = map.get(region);
                return email;
            }
        }
        return email;

    }

}
